home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Macintosh Tracker Source / Tracker Client Folder / CMyDocument.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  52.1 KB  |  2,227 lines  |  [TEXT/KAHL]

  1. /* CMyDocument.c */
  2.  
  3. #define compilingmydocument_c
  4.  
  5. #include "CMyDocument.h"
  6. #include "MenuController.h"
  7. #include "CSaveBeforeClosing.h"
  8. #include "Memory.h"
  9. #include "CApplication.h"
  10. #include "File.h"
  11. #include "CSack.h"
  12. #include "Alert.h"
  13. #include "CArray.h"
  14. #include "PortableFile.h"
  15. #include "Error.h"
  16. #include "StandardFile.h"
  17. #include <Sound.h>
  18. #include "CSongList.h"
  19. #include "CRewindButton.h"
  20. #include "CFastForwardButton.h"
  21. #include "CStopButton.h"
  22. #include "CPlayButton.h"
  23. #include "CPauseButton.h"
  24. #include "CSkipToNextButton.h"
  25. #include "LocationConstants.h"
  26. #include "CStaticText.h"
  27. #include "StringUtils.h"
  28. #include "CCheckbox.h"
  29. #include "CNumberEdit.h"
  30. #include "CDefaultStereoOn.h"
  31. #include "CDefaultAntiAlias.h"
  32. #include "CDefaultSamplingRate.h"
  33. #include "CDefaultStereoMix.h"
  34. #include "CDefaultNumRepeats.h"
  35. #include "CDefaultSpeed.h"
  36. #include "CSpecificStereoOn.h"
  37. #include "CSpecificAntiAlias.h"
  38. #include "CSpecificSamplingRate.h"
  39. #include "CSpecificStereoMix.h"
  40. #include "CSpecificNumRepeats.h"
  41. #include "CSpecificSpeed.h"
  42. #include "COverrideStereoOn.h"
  43. #include "COverrideAntiAlias.h"
  44. #include "COverrideSamplingRate.h"
  45. #include "COverrideStereoMix.h"
  46. #include "COverrideNumRepeats.h"
  47. #include "COverrideSpeed.h"
  48. #include "CDividerLine.h"
  49. #include "CMyApplication.h"
  50. #include "CSpecificVolume.h"
  51. #include "CDefaultVolume.h"
  52. #include "COverrideVolume.h"
  53. #include "CAutoNextSong.h"
  54. #include "CRepeat.h"
  55. #include "CAutoStartSongs.h"
  56. #include "CRandomize.h"
  57. #include "CNumOutputBits.h"
  58. #include "Compatibility.h"
  59.  
  60.  
  61. #define UntitledStringID (6592L*65536L + 1)
  62. #define SeparatorID (6592L*65536L + 2)
  63. #define EVENTDELAY (15)
  64.  
  65. #define CouldntSaveSongID (5120L*65536L + 1)
  66. #define ErrorOccurredWhileLoadingID (5120L*65536L + 2)
  67.  
  68. #define MAXRANDOMTRIESBEFOREGIVINGUP (50)
  69.  
  70.  
  71. /* */                CMyDocument::CMyDocument()
  72.     {
  73.         CArray*                SongTemp;
  74.         Handle                Temp;
  75.  
  76.         SongTemp = new CArray;
  77.         SongTemp->IArray(sizeof(SongRec),16);
  78.         ListOfSongs = SongTemp;
  79.  
  80.         RootWindow = NIL;
  81.         EverSaved = False;
  82.         UpToDate = True;
  83.         FileOpenFlag = False;
  84.  
  85.         SamplingRate = 22254;
  86.         StereoOn = False;
  87.         StereoMix = 0;
  88.         AntiAliasing = True;
  89.         Speed = 50;
  90.         NumRepeats = 1;
  91.         Volume = 48;
  92.         AutoNextSong = True;
  93.         Repeat = False;
  94.         AutoStartSongs = True;
  95.         Randomize = False;
  96.         UseSixteenBitMode = False;
  97.  
  98.         Selection = -1;
  99.  
  100.         SongToStart = -1;
  101.         PlayerExists = False;
  102.         PlayNextWhenThisOneStops = False;
  103.         Playing = -1;
  104.  
  105.         GetDateTime((void*)&randSeed);
  106.  
  107.         Temp = GetCString(UntitledStringID);
  108.         Handle2PString(Temp,TheFile.name);
  109.         ReleaseHandle(Temp);
  110.     }
  111.  
  112.  
  113. /* */                CMyDocument::~CMyDocument()
  114.     {
  115.         long                Scan;
  116.         SongRec            Thang;
  117.  
  118.         DeregisterIdler(this);
  119.  
  120.         if (RootWindow != NIL)
  121.             {
  122.                 delete RootWindow;
  123.             }
  124.  
  125.         for (Scan = 0; Scan < ListOfSongs->GetNumElements(); Scan += 1)
  126.             {
  127.                 ListOfSongs->GetElement(Scan,&Thang);
  128.                 ReleaseHandle((Handle)Thang.SongLocation);
  129.             }
  130.         delete ListOfSongs;
  131.  
  132.         if (FileOpenFlag)
  133.             {
  134.                 FCloseFile(FileRef);
  135.             }
  136.     }
  137.  
  138.  
  139. void                CMyDocument::DoNewFile(void)
  140.     {
  141.         MakeNewWindow();
  142.     }
  143.  
  144.  
  145. MyBoolean        CMyDocument::GoAway(void)
  146.     {
  147.         if (!UpToDate && EverSaved)
  148.             {
  149.                 CSaveBeforeClosingWindow*        Saver;
  150.                 MyBoolean                                        Result;
  151.  
  152.                 Saver = new CSaveBeforeClosingWindow;
  153.                 HLock((Handle)this);
  154.                 Result = Saver->SaveBeforeClosing(TheFile.name);
  155.                 HUnlock((Handle)this);
  156.                 switch (Result)
  157.                     {
  158.                         case Yes_Save:
  159.                             if (!SaveFile())
  160.                                 {
  161.                                     return False;
  162.                                 }
  163.                             break;
  164.                         case No_Save:
  165.                             break;
  166.                         case Cancel_Close:
  167.                             return False;
  168.                     }
  169.             }
  170.  
  171.         if (PlayerExists)
  172.             {
  173.                 Application->KillPlayer(OurPlayer);
  174.             }
  175.  
  176.         delete this;
  177.         return True;
  178.     }
  179.  
  180.  
  181. void                CMyDocument::DoPrint(void)
  182.     {
  183.     }
  184.  
  185.  
  186. void                CMyDocument::DoOpenFile(FSSpec* TheSpec)
  187.     {
  188.         short                    LocalRef;
  189.         ulong                    SongCount;
  190.  
  191.         /* reading in all them alias records */
  192.         TheFile = *TheSpec;
  193.         if (FOpenFile(TheSpec,&LocalRef) != noErr)
  194.             {
  195.                 /* error */
  196.             }
  197.         FileOpenFlag = True;
  198.         FileRef = LocalRef;
  199.  
  200.         ResetErrorCheck();
  201.         SamplingRate = (ushort)RShort(LocalRef);
  202.         StereoOn = RChar(LocalRef);
  203.         StereoMix = RShort(LocalRef);
  204.         AntiAliasing = RChar(LocalRef);
  205.         Speed = RShort(LocalRef);
  206.         NumRepeats = RShort(LocalRef);
  207.         Volume = RShort(LocalRef);
  208.         AutoNextSong = RChar(LocalRef);
  209.         Repeat = RChar(LocalRef);
  210.         AutoStartSongs = RChar(LocalRef);
  211.         Randomize = RChar(LocalRef);
  212.  
  213.         SongCount = RShort(LocalRef);
  214.         while (SongCount > 0)
  215.             {
  216.                 ulong                        AliasLength;
  217.                 SongRec                    DaAlias;
  218.                 long                        NewEntry;
  219.  
  220.                 DaAlias.SamplingRateOverrideDefault = RChar(LocalRef);
  221.                 DaAlias.SamplingRate = (ushort)RShort(LocalRef);
  222.                 DaAlias.StereoOnOverrideDefault = RChar(LocalRef);
  223.                 DaAlias.StereoOn = RShort(LocalRef);
  224.                 DaAlias.StereoMixOverrideDefault = RChar(LocalRef);
  225.                 DaAlias.StereoMix = RShort(LocalRef);
  226.                 DaAlias.AntiAliasingOverrideDefault = RChar(LocalRef);
  227.                 DaAlias.AntiAliasing = RShort(LocalRef);
  228.                 DaAlias.SpeedOverrideDefault = RChar(LocalRef);
  229.                 DaAlias.Speed = RShort(LocalRef);
  230.                 DaAlias.NumRepeatsOverrideDefault = RChar(LocalRef);
  231.                 DaAlias.NumRepeats = RShort(LocalRef);
  232.                 DaAlias.VolumeOverrideDefault = RChar(LocalRef);
  233.                 DaAlias.Volume = RShort(LocalRef);
  234.                 DaAlias.Tracker = RChar(LocalRef);
  235.                 FReadBlock(LocalRef,(char*)DaAlias.SongName,SongNameLength);
  236.                 AliasLength = RLong(LocalRef);
  237.                 DaAlias.SongLocation = (AliasRecord**)AllocHandle(AliasLength);
  238.                 HLock((Handle)DaAlias.SongLocation);
  239.                 FReadBlock(LocalRef,(char*)*DaAlias.SongLocation,AliasLength);
  240.                 HUnlock((Handle)DaAlias.SongLocation);
  241.                 DaAlias.PlayedFlag = False;
  242.                 NewEntry = ListOfSongs->AppendElement();
  243.                 ListOfSongs->PutElement(NewEntry,&DaAlias);
  244.                 SongCount -= 1;
  245.             }
  246.         if (ErrorOccurred())
  247.             {
  248.                 AlertError(ErrorOccurredWhileLoadingID,NIL);
  249.             }
  250.         MakeNewWindow();
  251.         SongList->RecalculateScrollBars();
  252.         if ((LastModifiers & controlKey) == 0)
  253.             {
  254.                 /* if they were NOT holding down the control key, then we want */
  255.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  256.                 RelinquishCPU();
  257.             }
  258.         if (AutoStartSongs && ((LastModifiers & controlKey) == 0))
  259.             {
  260.                 /* if they want to autostart songs upon opening the document AND */
  261.                 /* they didn't hold down the command key while selecting "open" */
  262.                 /* (or starting the program) then we can do it. */
  263.                 if (Randomize)
  264.                     {
  265.                         StartRandomSong();
  266.                     }
  267.                  else
  268.                     {
  269.                         StartThisSong(0);
  270.                     }
  271.             }
  272.         EverSaved = True;
  273.     }
  274.  
  275.  
  276. MyBoolean        CMyDocument::SaveFile(void)
  277.     {
  278.         if (EverSaved)
  279.             {
  280.                 WriteData();
  281.                 return True;
  282.             }
  283.          else
  284.             {
  285.                 return SaveFileAs();
  286.             }
  287.     }
  288.  
  289.  
  290. MyBoolean        CMyDocument::SaveFileAs(void)
  291.     {
  292.         FSSpec            NewInfo;
  293.         MyBoolean        Result;
  294.         MyBoolean        Replacing;
  295.  
  296.         HLock((Handle)this);
  297.         Result = FPutFile(TheFile.name,&NewInfo,&Replacing);
  298.         if (Result)
  299.             {
  300.                 if (Replacing)
  301.                     {
  302.                         FDeleteFile(&NewInfo);
  303.                     }
  304.                 TheFile = NewInfo;
  305.                 FCreate(&NewInfo,CREATORCODE,FILETYPE1);
  306.                 FOpenFile(&NewInfo,&FileRef);
  307.                 FileOpenFlag = True;
  308.                 WriteData();
  309.                 EverSaved = True;
  310.                 SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  311.             }
  312.         HUnlock((Handle)this);
  313.         return Result;
  314.     }
  315.  
  316.  
  317. void                CMyDocument::WriteData(void)
  318.     {
  319.         ulong                    SongCount;
  320.         ulong                    SongScan;
  321.         long                    FilePosTemp;
  322.  
  323.         ERROR(!FileOpenFlag,PRERR(ForceAbort,"CMyDocument::WriteData called when "
  324.             "no file was open for writing."));
  325.  
  326.         SpecificSamplingRateBox->StoreValue();
  327.         SpecificStereoMixBox->StoreValue();
  328.         SpecificNumRepeatsBox->StoreValue();
  329.         SpecificSpeedBox->StoreValue();
  330.         SpecificVolumeBox->StoreValue();
  331.         DefaultSamplingRateBox->StoreValue();
  332.         DefaultStereoMixBox->StoreValue();
  333.         DefaultNumRepeatsBox->StoreValue();
  334.         DefaultSpeedBox->StoreValue();
  335.         DefaultVolumeBox->StoreValue();
  336.  
  337.         ResetErrorCheck();
  338.         FSetFilePos(FileRef,0);
  339.  
  340.         WShort(FileRef,SamplingRate);
  341.         WChar(FileRef,StereoOn);
  342.         WShort(FileRef,StereoMix);
  343.         WChar(FileRef,AntiAliasing);
  344.         WShort(FileRef,Speed);
  345.         WShort(FileRef,NumRepeats);
  346.         WShort(FileRef,Volume);
  347.         WChar(FileRef,AutoNextSong);
  348.         WChar(FileRef,Repeat);
  349.         WChar(FileRef,AutoStartSongs);
  350.         WChar(FileRef,Randomize);
  351.  
  352.         SongCount = ListOfSongs->GetNumElements();
  353.         WShort(FileRef,SongCount);
  354.         for (SongScan = 0; SongScan < SongCount; SongScan += 1)
  355.             {
  356.                 SongRec            Song;
  357.                 ulong                AliasSize;
  358.  
  359.                 ListOfSongs->GetElement(SongScan,&Song);
  360.                 WChar(FileRef,Song.SamplingRateOverrideDefault);
  361.                 WShort(FileRef,Song.SamplingRate);
  362.                 WChar(FileRef,Song.StereoOnOverrideDefault);
  363.                 WShort(FileRef,Song.StereoOn);
  364.                 WChar(FileRef,Song.StereoMixOverrideDefault);
  365.                 WShort(FileRef,Song.StereoMix);
  366.                 WChar(FileRef,Song.AntiAliasingOverrideDefault);
  367.                 WShort(FileRef,Song.AntiAliasing);
  368.                 WChar(FileRef,Song.SpeedOverrideDefault);
  369.                 WShort(FileRef,Song.Speed);
  370.                 WChar(FileRef,Song.NumRepeatsOverrideDefault);
  371.                 WShort(FileRef,Song.NumRepeats);
  372.                 WChar(FileRef,Song.VolumeOverrideDefault);
  373.                 WShort(FileRef,Song.Volume);
  374.                 WChar(FileRef,Song.Tracker);
  375.                 FWriteBlock(FileRef,(char*)Song.SongName,SongNameLength);
  376.                 AliasSize = HandleSize((Handle)Song.SongLocation);
  377.                 WLong(FileRef,AliasSize);
  378.                 HLock((Handle)Song.SongLocation);
  379.                 FWriteBlock(FileRef,(char*)*Song.SongLocation,AliasSize);
  380.                 HUnlock((Handle)Song.SongLocation);
  381.             }
  382.         FGetFilePos(FileRef,&FilePosTemp);
  383.         FSetEOF(FileRef,FilePosTemp);
  384.         if (ErrorOccurred())
  385.             {
  386.                 AlertError(CouldntSaveSongID,NIL);
  387.             }
  388.          else
  389.             {
  390.                 UpToDate = True;
  391.             }
  392.     }
  393.  
  394.  
  395. void                CMyDocument::AddSong(FSSpec* TheSpec)
  396.     {
  397.         AliasRecord**            SystemAlias;
  398.         SongRec                        MyAlias;
  399.         long                            IndexToStoreAt;
  400.         OSErr                            Error;
  401.         short                            Scan;
  402.  
  403.         for (Scan = 0; Scan < sizeof(MyAlias); Scan += 1)
  404.             {
  405.                 ((char*)&MyAlias)[Scan] = 0;
  406.             }
  407.         MyAlias.SamplingRateOverrideDefault = False;
  408.         MyAlias.StereoOnOverrideDefault = False;
  409.         MyAlias.StereoMixOverrideDefault = False;
  410.         MyAlias.AntiAliasingOverrideDefault = False;
  411.         MyAlias.SpeedOverrideDefault = False;
  412.         MyAlias.NumRepeatsOverrideDefault = False;
  413.         MyAlias.VolumeOverrideDefault = False;
  414.         MyAlias.SamplingRate = SamplingRate;
  415.         MyAlias.StereoOn = StereoOn;
  416.         MyAlias.StereoMix = StereoMix;
  417.         MyAlias.AntiAliasing = AntiAliasing;
  418.         MyAlias.Speed = Speed;
  419.         MyAlias.NumRepeats = NumRepeats;
  420.         MyAlias.Volume = Volume;
  421.         MyAlias.Tracker = False;
  422.         MemCpy((char*)MyAlias.SongName,(char*)TheSpec->name,TheSpec->name[0] + 1);
  423.         if (MyAlias.SongName[0] > SongNameLength - 1)
  424.             {
  425.                 MyAlias.SongName[0] = SongNameLength - 1;
  426.             }
  427.         Error = NewAlias(NIL,TheSpec,&SystemAlias);
  428.         MyAlias.SongLocation = (AliasRecord**)DupSysHandle((Handle)SystemAlias);
  429.         DisposHandle((Handle)SystemAlias);
  430.         MyAlias.PlayedFlag = False;
  431.         IndexToStoreAt = ListOfSongs->AppendElement();
  432.         ListOfSongs->PutElement(IndexToStoreAt,&MyAlias);
  433.         EXECUTE(ListOfSongs->GetElement(IndexToStoreAt,&MyAlias);)
  434.         SongList->Redraw(IndexToStoreAt,IndexToStoreAt);
  435.         SongList->RecalculateScrollBars();
  436.         if ((LastModifiers & controlKey) == 0)
  437.             {
  438.                 /* if they were NOT holding down the control key, then we want */
  439.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  440.                 RelinquishCPU();
  441.             }
  442.         if ((Playing == -1) && (SongToStart == -1) && AutoStartSongs
  443.             && ((LastModifiers & controlKey) == 0))
  444.             {
  445.                 StartThisSong(IndexToStoreAt);
  446.             }
  447.         UpToDate = False;
  448.     }
  449.  
  450.  
  451. void                CMyDocument::CancelCurrentSong(void)
  452.     {
  453.         if (PlayerExists)
  454.             {
  455.                 Application->KillPlayer(OurPlayer);
  456.                 PlayerState = PlayerDying;
  457.             }
  458.         PlayNextWhenThisOneStops = False;
  459.     }
  460.  
  461.  
  462. void                CMyDocument::StartThisSong(long SongIndex)
  463.     {
  464.         SongRec                    Temp;
  465.  
  466.         if (Playing != -1)
  467.             {
  468.                 CancelCurrentSong();
  469.             }
  470.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  471.             {
  472.                 RegisterIdler(this,EVENTDELAY);
  473.                 SongToStart = SongIndex;
  474.                 ListOfSongs->GetElement(SongIndex,&Temp);
  475.                 Temp.PlayedFlag = True;
  476.                 ListOfSongs->PutElement(SongIndex,&Temp);
  477.             }
  478.         PlayNextWhenThisOneStops = AutoNextSong;
  479.     }
  480.  
  481.  
  482. void                CMyDocument::RemoveSongFromList(long SongIndex)
  483.     {
  484.         SongRec                Temp;
  485.  
  486.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  487.             {
  488.                 if (SongIndex == Playing)
  489.                     {
  490.                         CancelCurrentSong();
  491.                     }
  492.                 if (SongIndex < Playing)
  493.                     {
  494.                         Playing -= 1;
  495.                     }
  496.                 UpToDate = False;
  497.                 ListOfSongs->GetElement(SongIndex,&Temp);
  498.                 ReleaseHandle((Handle)Temp.SongLocation);
  499.                 ListOfSongs->DeleteElement(SongIndex);
  500.                 SongList->Redraw(SongIndex,ListOfSongs->GetNumElements());
  501.             }
  502.     }
  503.  
  504.  
  505. void                CMyDocument::MakeNewWindow(void)
  506.     {
  507.         CWindow*                        Window;
  508.         LongPoint                        Start;
  509.         LongPoint                        Extent;
  510.         CStaticText*                StaticText;
  511.         CPlayButton*                PlayButton;
  512.         CDividerLine*                DividerLine;
  513.  
  514.  
  515.         MoveHHi((Handle)this);
  516.         HLock((Handle)this);
  517.  
  518.  
  519.         Window = new CWindow;
  520.         GetRect(WindowLocsID,&Start,&Extent);
  521.         Start = CenterRect(Extent,MainScreenSize());
  522.         Window->IWindow(Start,Extent,ModelessWindow,NoGrowable,NoZoomable);
  523.         RootWindow = Window;
  524.         SetWTitle(Window->MyGrafPtr,TheFile.name);
  525.  
  526.  
  527.         SongList = new CSongList;
  528.         SongList->ISongList(this,Window);
  529.  
  530.  
  531.         RewindButton = new CRewindButton;
  532.         RewindButton->IRewindButton(this,Window);
  533.  
  534.         StopButton = new CStopButton;
  535.         StopButton->IStopButton(this,Window);
  536.  
  537.         PlayButton = new CPlayButton;
  538.         PlayButton->IPlayButton(this,Window);
  539.         PausePlayButton = PlayButton;
  540.  
  541.         FastForwardButton = new CFastForwardButton;
  542.         FastForwardButton->IFastForwardButton(this,Window);
  543.  
  544.         SkipToNextButton = new CSkipToNextButton;
  545.         SkipToNextButton->ISkipToNextButton(this,Window);
  546.  
  547.  
  548.         StaticText = new CStaticText;
  549.         GetRect(DefaultSettingsID,&Start,&Extent);
  550.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSettingsID),
  551.             applFont,9,Window,Window,JustifyLeft);
  552.  
  553.         StaticText = new CStaticText;
  554.         GetRect(DefaultFrequencyID,&Start,&Extent);
  555.         StaticText->IStaticText(Start,Extent,GetCString(DefaultFrequencyID),
  556.             applFont,9,Window,Window,JustifyLeft);
  557.  
  558.         StaticText = new CStaticText;
  559.         GetRect(DefaultSpeedID,&Start,&Extent);
  560.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSpeedID),
  561.             applFont,9,Window,Window,JustifyLeft);
  562.  
  563.         StaticText = new CStaticText;
  564.         GetRect(DefaultRepeatsID,&Start,&Extent);
  565.         StaticText->IStaticText(Start,Extent,GetCString(DefaultRepeatsID),
  566.             applFont,9,Window,Window,JustifyLeft);
  567.  
  568.         StaticText = new CStaticText;
  569.         GetRect(DefaultMixID,&Start,&Extent);
  570.         StaticText->IStaticText(Start,Extent,GetCString(DefaultMixID),
  571.             applFont,9,Window,Window,JustifyLeft);
  572.  
  573.         StaticText = new CStaticText;
  574.         GetRect(DefaultVolumeID,&Start,&Extent);
  575.         StaticText->IStaticText(Start,Extent,GetCString(DefaultVolumeID),
  576.             applFont,9,Window,Window,JustifyLeft);
  577.  
  578.         SpecificSamplingRateText = new CStaticText;
  579.         GetRect(SpecificFrequencyID,&Start,&Extent);
  580.         SpecificSamplingRateText->IStaticText(Start,Extent,GetCString(SpecificFrequencyID),
  581.             applFont,9,Window,Window,JustifyLeft);
  582.  
  583.         SpecificSpeedText = new CStaticText;
  584.         GetRect(SpecificSpeedID,&Start,&Extent);
  585.         SpecificSpeedText->IStaticText(Start,Extent,GetCString(SpecificSpeedID),
  586.             applFont,9,Window,Window,JustifyLeft);
  587.  
  588.         SpecificNumRepeatsText = new CStaticText;
  589.         GetRect(SpecificRepeatsID,&Start,&Extent);
  590.         SpecificNumRepeatsText->IStaticText(Start,Extent,GetCString(SpecificRepeatsID),
  591.             applFont,9,Window,Window,JustifyLeft);
  592.  
  593.         SpecificStereoMixText = new CStaticText;
  594.         GetRect(SpecificMixID,&Start,&Extent);
  595.         SpecificStereoMixText->IStaticText(Start,Extent,GetCString(SpecificMixID),
  596.             applFont,9,Window,Window,JustifyLeft);
  597.  
  598.         SpecificVolumeText = new CStaticText;
  599.         GetRect(SpecificVolumeID,&Start,&Extent);
  600.         SpecificVolumeText->IStaticText(Start,Extent,GetCString(SpecificVolumeID),
  601.             applFont,9,Window,Window,JustifyLeft);
  602.  
  603.         AutoNextSongBox = new CAutoNextSong;
  604.         AutoNextSongBox->IAutoNextSong(this,Window);
  605.  
  606.         RepeatBox = new CRepeat;
  607.         RepeatBox->IRepeat(this,Window);
  608.  
  609.         AutoStartSongsBox = new CAutoStartSongs;
  610.         AutoStartSongsBox->IAutoStartSongs(this,Window);
  611.  
  612.         RandomizeBox = new CRandomize;
  613.         RandomizeBox->IRandomize(this,Window);
  614.  
  615.         DividerLine = new CDividerLine;
  616.         DividerLine->IDividerLine(Window);
  617.  
  618.  
  619.         DefaultStereoOnBox = new CDefaultStereoOn;
  620.         DefaultStereoOnBox->IDefaultStereoOn(this,Window);
  621.  
  622.         DefaultAntiAliasingBox = new CDefaultAntiAliasing;
  623.         DefaultAntiAliasingBox->IDefaultAntiAliasing(this,Window);
  624.  
  625.         DefaultVolumeBox = new CDefaultVolume;
  626.         DefaultVolumeBox->IDefaultVolume(this,Window);
  627.         DefaultVolumeBox->SetValue(Volume);
  628.  
  629.         DefaultSamplingRateBox = new CDefaultSamplingRate;
  630.         DefaultSamplingRateBox->IDefaultSamplingRate(this,Window);
  631.         DefaultSamplingRateBox->SetValue(SamplingRate);
  632.  
  633.         DefaultSpeedBox = new CDefaultSpeed;
  634.         DefaultSpeedBox->IDefaultSpeed(this,Window);
  635.         DefaultSpeedBox->SetValue(Speed);
  636.  
  637.         DefaultNumRepeatsBox = new CDefaultNumRepeats;
  638.         DefaultNumRepeatsBox->IDefaultNumRepeats(this,Window);
  639.         DefaultNumRepeatsBox->SetValue(NumRepeats);
  640.  
  641.         DefaultStereoMixBox = new CDefaultStereoMix;
  642.         DefaultStereoMixBox->IDefaultStereoMix(this,Window);
  643.         DefaultStereoMixBox->SetValue(StereoMix);
  644.  
  645.         NumOutputBitsBox = new CNumOutputBits;
  646.         NumOutputBitsBox->INumOutputBits(this,Window);
  647.  
  648.  
  649.         SpecificStereoOnBox = new CSpecificStereoOn;
  650.         SpecificStereoOnBox->ISpecificStereoOn(this,Window);
  651.  
  652.         SpecificAntiAliasingBox = new CSpecificAntiAliasing;
  653.         SpecificAntiAliasingBox->ISpecificAntiAliasing(this,Window);
  654.  
  655.         SpecificVolumeBox = new CSpecificVolume;
  656.         SpecificVolumeBox->ISpecificVolume(this,Window);
  657.  
  658.         SpecificSamplingRateBox = new CSpecificSamplingRate;
  659.         SpecificSamplingRateBox->ISpecificSamplingRate(this,Window);
  660.  
  661.         SpecificSpeedBox = new CSpecificSpeed;
  662.         SpecificSpeedBox->ISpecificSpeed(this,Window);
  663.  
  664.         SpecificNumRepeatsBox = new CSpecificNumRepeats;
  665.         SpecificNumRepeatsBox->ISpecificNumRepeats(this,Window);
  666.  
  667.         SpecificStereoMixBox = new CSpecificStereoMix;
  668.         SpecificStereoMixBox->ISpecificStereoMix(this,Window);
  669.  
  670.  
  671.         OverrideStereoOnBox = new COverrideStereoOn;
  672.         OverrideStereoOnBox->IOverrideStereoOn(this,Window);
  673.  
  674.         OverrideAntiAliasingBox = new COverrideAntiAliasing;
  675.         OverrideAntiAliasingBox->IOverrideAntiAliasing(this,Window);
  676.  
  677.         OverrideSamplingRateBox = new COverrideSamplingRate;
  678.         OverrideSamplingRateBox->IOverrideSamplingRate(this,Window);
  679.  
  680.         OverrideStereoMixBox = new COverrideStereoMix;
  681.         OverrideStereoMixBox->IOverrideStereoMix(this,Window);
  682.  
  683.         OverrideNumRepeatsBox = new COverrideNumRepeats;
  684.         OverrideNumRepeatsBox->IOverrideNumRepeats(this,Window);
  685.  
  686.         OverrideSpeedBox = new COverrideSpeed;
  687.         OverrideSpeedBox->IOverrideSpeed(this,Window);
  688.  
  689.         OverrideVolumeBox = new COverrideVolume;
  690.         OverrideVolumeBox->IOverrideVolume(this,Window);
  691.  
  692.  
  693.         SpecificStereoOnBox->DoDisable();
  694.         SpecificAntiAliasingBox->DoDisable();
  695.         SpecificSamplingRateBox->DoDisable();
  696.         SpecificStereoMixBox->DoDisable();
  697.         SpecificNumRepeatsBox->DoDisable();
  698.         SpecificSpeedBox->DoDisable();
  699.         SpecificVolumeBox->DoDisable();
  700.         SpecificSamplingRateText->DoDisable();
  701.         SpecificStereoMixText->DoDisable();
  702.         SpecificNumRepeatsText->DoDisable();
  703.         SpecificSpeedText->DoDisable();
  704.         SpecificVolumeText->DoDisable();
  705.  
  706.         OverrideStereoOnBox->DoDisable();
  707.         OverrideAntiAliasingBox->DoDisable();
  708.         OverrideSamplingRateBox->DoDisable();
  709.         OverrideStereoMixBox->DoDisable();
  710.         OverrideNumRepeatsBox->DoDisable();
  711.         OverrideSpeedBox->DoDisable();
  712.         OverrideVolumeBox->DoDisable();
  713.  
  714.         if (StereoOn)
  715.             {
  716.                 DefaultStereoOnBox->DoThang();
  717.             }
  718.  
  719.         if (AntiAliasing)
  720.             {
  721.                 DefaultAntiAliasingBox->DoThang();
  722.             }
  723.  
  724.         if (AutoNextSong)
  725.             {
  726.                 AutoNextSongBox->DoThang();
  727.             }
  728.  
  729.         if (Repeat)
  730.             {
  731.                 RepeatBox->DoThang();
  732.             }
  733.  
  734.         if (AutoStartSongs)
  735.             {
  736.                 AutoStartSongsBox->DoThang();
  737.             }
  738.  
  739.         if (Randomize)
  740.             {
  741.                 RandomizeBox->DoThang();
  742.             }
  743.  
  744.         RewindButton->DoDisable();
  745.         StopButton->DoDisable();
  746.         PausePlayButton->DoEnable();
  747.         FastForwardButton->DoDisable();
  748.         SkipToNextButton->DoDisable();
  749.  
  750.  
  751.         HUnlock((Handle)this);
  752.     }
  753.  
  754.  
  755. void                CMyDocument::SetStereoOn(MyBoolean NewStereoOn)
  756.     {
  757.         SongRec                Temp;
  758.  
  759.         if (Selection == -1)
  760.             {
  761.                 return;
  762.             }
  763.  
  764.         UpToDate = False;
  765.         ListOfSongs->GetElement(Selection,&Temp);
  766.         Temp.StereoOn = NewStereoOn;
  767.         ListOfSongs->PutElement(Selection,&Temp);
  768.         if (SpecificStereoOnBox->State != NewStereoOn)
  769.             {
  770.                 SpecificStereoOnBox->DoThang();
  771.             }
  772.         if (Selection == Playing)
  773.             {
  774.                 SendMessage((short)NewStereoOn,keyStereoOn);
  775.             }
  776.     }
  777.  
  778.  
  779. void                CMyDocument::SetNumOutputBits(MyBoolean SixteenBitMode)
  780.     {
  781.         UseSixteenBitMode = SixteenBitMode;
  782.         if (NumOutputBitsBox->State != SixteenBitMode)
  783.             {
  784.                 NumOutputBitsBox->DoThang();
  785.             }
  786.     }
  787.  
  788.  
  789. void                CMyDocument::SetAntiAliasing(MyBoolean NewAntiAliasing)
  790.     {
  791.         SongRec                Temp;
  792.  
  793.         if (Selection == -1)
  794.             {
  795.                 return;
  796.             }
  797.  
  798.         UpToDate = False;
  799.         ListOfSongs->GetElement(Selection,&Temp);
  800.         Temp.AntiAliasing = NewAntiAliasing;
  801.         ListOfSongs->PutElement(Selection,&Temp);
  802.         if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  803.             {
  804.                 SpecificAntiAliasingBox->DoThang();
  805.             }
  806.         if (Selection == Playing)
  807.             {
  808.                 SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  809.             }
  810.     }
  811.  
  812.  
  813. void                CMyDocument::SetSamplingRate(ulong NewSamplingRate)
  814.     {
  815.         SongRec                Temp;
  816.  
  817.         if (Selection == -1)
  818.             {
  819.                 return;
  820.             }
  821.  
  822.         UpToDate = False;
  823.         ListOfSongs->GetElement(Selection,&Temp);
  824.         Temp.SamplingRate = NewSamplingRate;
  825.         ListOfSongs->PutElement(Selection,&Temp);
  826.         SpecificSamplingRateBox->SetValue(NewSamplingRate);
  827.         if (Selection == Playing)
  828.             {
  829.                 SendMessage((short)NewSamplingRate,keySamplingRate);
  830.             }
  831.     }
  832.  
  833.  
  834. void                CMyDocument::SetStereoMix(short NewStereoMix)
  835.     {
  836.         SongRec                Temp;
  837.  
  838.         if (Selection == -1)
  839.             {
  840.                 return;
  841.             }
  842.  
  843.         UpToDate = False;
  844.         ListOfSongs->GetElement(Selection,&Temp);
  845.         Temp.StereoMix = NewStereoMix;
  846.         ListOfSongs->PutElement(Selection,&Temp);
  847.         SpecificStereoMixBox->SetValue(NewStereoMix);
  848.         if (Selection == Playing)
  849.             {
  850.                 SendMessage((short)NewStereoMix,keyStereoMix);
  851.             }
  852.     }
  853.  
  854.  
  855. void                CMyDocument::SetNumRepeats(short NewNumRepeats)
  856.     {
  857.         SongRec                Temp;
  858.  
  859.         if (Selection == -1)
  860.             {
  861.                 return;
  862.             }
  863.  
  864.         UpToDate = False;
  865.         ListOfSongs->GetElement(Selection,&Temp);
  866.         Temp.NumRepeats = NewNumRepeats;
  867.         ListOfSongs->PutElement(Selection,&Temp);
  868.         SpecificNumRepeatsBox->SetValue(NewNumRepeats);
  869.         if (Selection == Playing)
  870.             {
  871.                 SendMessage((short)NewNumRepeats,keyNumRepeats);
  872.             }
  873.     }
  874.  
  875.  
  876. void                CMyDocument::SetSpeed(short NewSpeed)
  877.     {
  878.         SongRec                Temp;
  879.  
  880.         if (Selection == -1)
  881.             {
  882.                 return;
  883.             }
  884.  
  885.         UpToDate = False;
  886.         ListOfSongs->GetElement(Selection,&Temp);
  887.         Temp.Speed = NewSpeed;
  888.         ListOfSongs->PutElement(Selection,&Temp);
  889.         SpecificSpeedBox->SetValue(NewSpeed);
  890.         if (Selection == Playing)
  891.             {
  892.                 SendMessage((short)NewSpeed,keySpeed);
  893.             }
  894.     }
  895.  
  896.  
  897. void                CMyDocument::SetVolume(short NewVolume)
  898.     {
  899.         SongRec                Temp;
  900.  
  901.         if (Selection == -1)
  902.             {
  903.                 return;
  904.             }
  905.  
  906.         UpToDate = False;
  907.         ListOfSongs->GetElement(Selection,&Temp);
  908.         Temp.Volume = NewVolume;
  909.         ListOfSongs->PutElement(Selection,&Temp);
  910.         SpecificVolumeBox->SetValue(NewVolume);
  911.         if (Selection == Playing)
  912.             {
  913.                 SendMessage((short)NewVolume,keyLoudness);
  914.             }
  915.     }
  916.  
  917.  
  918. void                CMyDocument::SetOverrideStereoOn(MyBoolean Flag)
  919.     {
  920.         SongRec                Temp;
  921.  
  922.         if (Selection == -1)
  923.             {
  924.                 return;
  925.             }
  926.  
  927.         UpToDate = False;
  928.         ListOfSongs->GetElement(Selection,&Temp);
  929.         Temp.StereoOnOverrideDefault = Flag;
  930.         if (Flag)
  931.             {
  932.                 Temp.StereoOn = StereoOn;
  933.                 SpecificStereoOnBox->DoEnable();
  934.                 if (SpecificStereoOnBox->State != Temp.StereoOn)
  935.                     {
  936.                         SpecificStereoOnBox->DoThang();
  937.                     }
  938.             }
  939.          else
  940.             {
  941.                 SpecificStereoOnBox->DoDisable();
  942.                 if (Selection == Playing)
  943.                     {
  944.                         SendMessage((short)StereoOn,keyStereoOn);
  945.                     }
  946.             }
  947.         ListOfSongs->PutElement(Selection,&Temp);
  948.     }
  949.  
  950.  
  951. void                CMyDocument::SetOverrideAntiAliasing(MyBoolean Flag)
  952.     {
  953.         SongRec                Temp;
  954.  
  955.         if (Selection == -1)
  956.             {
  957.                 return;
  958.             }
  959.  
  960.         UpToDate = False;
  961.         ListOfSongs->GetElement(Selection,&Temp);
  962.         Temp.AntiAliasingOverrideDefault = Flag;
  963.         if (Flag)
  964.             {
  965.                 Temp.AntiAliasing = AntiAliasing;
  966.                 SpecificAntiAliasingBox->DoEnable();
  967.                 if (SpecificAntiAliasingBox->State != Temp.AntiAliasing)
  968.                     {
  969.                         SpecificAntiAliasingBox->DoThang();
  970.                     }
  971.             }
  972.          else
  973.             {
  974.                 SpecificAntiAliasingBox->DoDisable();
  975.                 if (Selection == Playing)
  976.                     {
  977.                         SendMessage((short)AntiAliasing,keyAntiAliasing);
  978.                     }
  979.             }
  980.         ListOfSongs->PutElement(Selection,&Temp);
  981.     }
  982.  
  983.  
  984. void                CMyDocument::SetOverrideSamplingRate(MyBoolean Flag)
  985.     {
  986.         SongRec                Temp;
  987.  
  988.         if (Selection == -1)
  989.             {
  990.                 return;
  991.             }
  992.  
  993.         UpToDate = False;
  994.         ListOfSongs->GetElement(Selection,&Temp);
  995.         Temp.SamplingRateOverrideDefault = Flag;
  996.         if (Flag)
  997.             {
  998.                 Temp.SamplingRate = SamplingRate;
  999.                 SpecificSamplingRateBox->DoEnable();
  1000.                 SpecificSamplingRateText->DoEnable();
  1001.                 if (SpecificSamplingRateBox->GetValue() != Temp.SamplingRate)
  1002.                     {
  1003.                         SpecificSamplingRateBox->SetValue(Temp.SamplingRate);
  1004.                     }
  1005.             }
  1006.          else
  1007.             {
  1008.                 SpecificSamplingRateBox->DoDisable();
  1009.                 SpecificSamplingRateText->DoDisable();
  1010.                 if (Selection == Playing)
  1011.                     {
  1012.                         SendMessage((short)SamplingRate,keySamplingRate);
  1013.                     }
  1014.             }
  1015.         ListOfSongs->PutElement(Selection,&Temp);
  1016.     }
  1017.  
  1018.  
  1019. void                CMyDocument::SetOverrideStereoMix(MyBoolean Flag)
  1020.     {
  1021.         SongRec                Temp;
  1022.  
  1023.         if (Selection == -1)
  1024.             {
  1025.                 return;
  1026.             }
  1027.  
  1028.         UpToDate = False;
  1029.         ListOfSongs->GetElement(Selection,&Temp);
  1030.         Temp.StereoMixOverrideDefault = Flag;
  1031.         if (Flag)
  1032.             {
  1033.                 Temp.StereoMix = StereoMix;
  1034.                 SpecificStereoMixBox->DoEnable();
  1035.                 SpecificStereoMixText->DoEnable();
  1036.                 if (SpecificStereoMixBox->GetValue() != Temp.StereoMix)
  1037.                     {
  1038.                         SpecificStereoMixBox->SetValue(Temp.StereoMix);
  1039.                     }
  1040.             }
  1041.          else
  1042.             {
  1043.                 SpecificStereoMixBox->DoDisable();
  1044.                 SpecificStereoMixText->DoDisable();
  1045.                 if (Selection == Playing)
  1046.                     {
  1047.                         SendMessage((short)StereoMix,keyStereoMix);
  1048.                     }
  1049.             }
  1050.         ListOfSongs->PutElement(Selection,&Temp);
  1051.     }
  1052.  
  1053.  
  1054. void                CMyDocument::SetOverrideNumRepeats(MyBoolean Flag)
  1055.     {
  1056.         SongRec                Temp;
  1057.  
  1058.         if (Selection == -1)
  1059.             {
  1060.                 return;
  1061.             }
  1062.  
  1063.         UpToDate = False;
  1064.         ListOfSongs->GetElement(Selection,&Temp);
  1065.         Temp.NumRepeatsOverrideDefault = Flag;
  1066.         if (Flag)
  1067.             {
  1068.                 Temp.NumRepeats = NumRepeats;
  1069.                 SpecificNumRepeatsBox->DoEnable();
  1070.                 SpecificNumRepeatsText->DoEnable();
  1071.                 if (SpecificNumRepeatsBox->GetValue() != Temp.NumRepeats)
  1072.                     {
  1073.                         SpecificNumRepeatsBox->SetValue(Temp.NumRepeats);
  1074.                     }
  1075.             }
  1076.          else
  1077.             {
  1078.                 SpecificNumRepeatsBox->DoDisable();
  1079.                 SpecificNumRepeatsText->DoDisable();
  1080.                 if (Selection == Playing)
  1081.                     {
  1082.                         SendMessage((short)NumRepeats,keyNumRepeats);
  1083.                     }
  1084.             }
  1085.         ListOfSongs->PutElement(Selection,&Temp);
  1086.     }
  1087.  
  1088.  
  1089. void                CMyDocument::SetOverrideSpeed(MyBoolean Flag)
  1090.     {
  1091.         SongRec                Temp;
  1092.  
  1093.         if (Selection == -1)
  1094.             {
  1095.                 return;
  1096.             }
  1097.  
  1098.         UpToDate = False;
  1099.         ListOfSongs->GetElement(Selection,&Temp);
  1100.         Temp.SpeedOverrideDefault = Flag;
  1101.         if (Flag)
  1102.             {
  1103.                 Temp.Speed = Speed;
  1104.                 SpecificSpeedBox->DoEnable();
  1105.                 SpecificSpeedText->DoEnable();
  1106.                 if (SpecificSpeedBox->GetValue() != Temp.Speed)
  1107.                     {
  1108.                         SpecificSpeedBox->SetValue(Temp.Speed);
  1109.                     }
  1110.             }
  1111.          else
  1112.             {
  1113.                 SpecificSpeedBox->DoDisable();
  1114.                 SpecificSpeedText->DoDisable();
  1115.                 if (Selection == Playing)
  1116.                     {
  1117.                         SendMessage((short)Speed,keySpeed);
  1118.                     }
  1119.             }
  1120.         ListOfSongs->PutElement(Selection,&Temp);
  1121.     }
  1122.  
  1123.  
  1124. void                CMyDocument::SetOverrideVolume(MyBoolean Flag)
  1125.     {
  1126.         SongRec                Temp;
  1127.  
  1128.         if (Selection == -1)
  1129.             {
  1130.                 return;
  1131.             }
  1132.  
  1133.         UpToDate = False;
  1134.         ListOfSongs->GetElement(Selection,&Temp);
  1135.         Temp.VolumeOverrideDefault = Flag;
  1136.         if (Flag)
  1137.             {
  1138.                 Temp.Volume = Volume;
  1139.                 SpecificVolumeBox->DoEnable();
  1140.                 SpecificVolumeText->DoEnable();
  1141.                 if (SpecificVolumeBox->GetValue() != Temp.Volume)
  1142.                     {
  1143.                         SpecificVolumeBox->SetValue(Temp.Volume);
  1144.                     }
  1145.             }
  1146.          else
  1147.             {
  1148.                 SpecificVolumeBox->DoDisable();
  1149.                 SpecificVolumeText->DoDisable();
  1150.                 if (Selection == Playing)
  1151.                     {
  1152.                         SendMessage((short)Volume,keyLoudness);
  1153.                     }
  1154.             }
  1155.         ListOfSongs->PutElement(Selection,&Temp);
  1156.     }
  1157.  
  1158.  
  1159. void                CMyDocument::SetDefaultStereoOn(MyBoolean NewStereoOn)
  1160.     {
  1161.         StereoOn = NewStereoOn;
  1162.         if (DefaultStereoOnBox->State != NewStereoOn)
  1163.             {
  1164.                 DefaultStereoOnBox->DoThang();
  1165.             }
  1166.         if (!OverrideStereoOnBox->State)
  1167.             {
  1168.                 if (SpecificStereoOnBox->State != NewStereoOn)
  1169.                     {
  1170.                         SpecificStereoOnBox->DoThang();
  1171.                     }
  1172.                 if (Selection == Playing)
  1173.                     {
  1174.                         SendMessage((short)NewStereoOn,keyStereoOn);
  1175.                     }
  1176.             }
  1177.         UpToDate = False;
  1178.     }
  1179.  
  1180.  
  1181. void                CMyDocument::SetDefaultAntiAliasing(MyBoolean NewAntiAliasing)
  1182.     {
  1183.         AntiAliasing = NewAntiAliasing;
  1184.         if (DefaultAntiAliasingBox->State != NewAntiAliasing)
  1185.             {
  1186.                 DefaultAntiAliasingBox->DoThang();
  1187.             }
  1188.         if (!OverrideAntiAliasingBox->State)
  1189.             {
  1190.                 if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  1191.                     {
  1192.                         SpecificAntiAliasingBox->DoThang();
  1193.                     }
  1194.                 if (Selection == Playing)
  1195.                     {
  1196.                         SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  1197.                     }
  1198.             }
  1199.         UpToDate = False;
  1200.     }
  1201.  
  1202.  
  1203. void                CMyDocument::SetDefaultSamplingRate(ulong NewSamplingRate)
  1204.     {
  1205.         SamplingRate = NewSamplingRate;
  1206.         if (DefaultSamplingRateBox->GetValue() != NewSamplingRate)
  1207.             {
  1208.                 DefaultSamplingRateBox->SetValue(NewSamplingRate);
  1209.             }
  1210.         if (!OverrideSamplingRateBox->State)
  1211.             {
  1212.                 if (SpecificSamplingRateBox->GetValue() != NewSamplingRate)
  1213.                     {
  1214.                         SpecificSamplingRateBox->SetValue(NewSamplingRate);
  1215.                     }
  1216.                 if (Selection == Playing)
  1217.                     {
  1218.                         SendMessage((short)NewSamplingRate,keySamplingRate);
  1219.                     }
  1220.             }
  1221.         UpToDate = False;
  1222.     }
  1223.  
  1224.  
  1225. void                CMyDocument::SetDefaultStereoMix(short NewStereoMix)
  1226.     {
  1227.         StereoMix = NewStereoMix;
  1228.         if (DefaultStereoMixBox->GetValue() != NewStereoMix)
  1229.             {
  1230.                 DefaultStereoMixBox->SetValue(NewStereoMix);
  1231.             }
  1232.         if (!OverrideStereoMixBox->State)
  1233.             {
  1234.                 if (SpecificStereoMixBox->GetValue() != NewStereoMix)
  1235.                     {
  1236.                         SpecificStereoMixBox->SetValue(NewStereoMix);
  1237.                     }
  1238.                 if (Selection == Playing)
  1239.                     {
  1240.                         SendMessage((short)NewStereoMix,keyStereoMix);
  1241.                     }
  1242.             }
  1243.         UpToDate = False;
  1244.     }
  1245.  
  1246.  
  1247. void                CMyDocument::SetDefaultNumRepeats(short NewNumRepeats)
  1248.     {
  1249.         NumRepeats = NewNumRepeats;
  1250.         if (DefaultNumRepeatsBox->GetValue() != NewNumRepeats)
  1251.             {
  1252.                 DefaultNumRepeatsBox->SetValue(NewNumRepeats);
  1253.             }
  1254.         if (!OverrideNumRepeatsBox->State)
  1255.             {
  1256.                 if (SpecificNumRepeatsBox->GetValue() != NewNumRepeats)
  1257.                     {
  1258.                         SpecificNumRepeatsBox->SetValue(NewNumRepeats);
  1259.                     }
  1260.                 if (Selection == Playing)
  1261.                     {
  1262.                         SendMessage((short)NewNumRepeats,keyNumRepeats);
  1263.                     }
  1264.             }
  1265.         UpToDate = False;
  1266.     }
  1267.  
  1268.  
  1269. void                CMyDocument::SetDefaultSpeed(short NewSpeed)
  1270.     {
  1271.         Speed = NewSpeed;
  1272.         if (DefaultSpeedBox->GetValue() != NewSpeed)
  1273.             {
  1274.                 DefaultSpeedBox->SetValue(NewSpeed);
  1275.             }
  1276.         if (!OverrideSpeedBox->State)
  1277.             {
  1278.                 if (SpecificSpeedBox->GetValue() != NewSpeed)
  1279.                     {
  1280.                         SpecificSpeedBox->SetValue(NewSpeed);
  1281.                     }
  1282.                 if (Selection == Playing)
  1283.                     {
  1284.                         SendMessage((short)NewSpeed,keySpeed);
  1285.                     }
  1286.             }
  1287.         UpToDate = False;
  1288.     }
  1289.  
  1290.  
  1291. void                CMyDocument::SetDefaultVolume(short NewVolume)
  1292.     {
  1293.         Volume = NewVolume;
  1294.         if (DefaultVolumeBox->GetValue() != NewVolume)
  1295.             {
  1296.                 DefaultVolumeBox->SetValue(NewVolume);
  1297.             }
  1298.         if (!OverrideVolumeBox->State)
  1299.             {
  1300.                 if (SpecificVolumeBox->GetValue() != NewVolume)
  1301.                     {
  1302.                         SpecificVolumeBox->SetValue(NewVolume);
  1303.                     }
  1304.                 if (Selection == Playing)
  1305.                     {
  1306.                         SendMessage((short)NewVolume,keyLoudness);
  1307.                     }
  1308.             }
  1309.         UpToDate = False;
  1310.     }
  1311.  
  1312.  
  1313. void                CMyDocument::SetTrackerServerToUse(TrackerTypes WhatKind)
  1314.     {
  1315.         SongRec                Temp;
  1316.  
  1317.         if (Selection == -1)
  1318.             {
  1319.                 return;
  1320.             }
  1321.  
  1322.         UpToDate = False;
  1323.         ListOfSongs->GetElement(Selection,&Temp);
  1324.         Temp.Tracker = WhatKind;
  1325.         ListOfSongs->PutElement(Selection,&Temp);
  1326.     }
  1327.  
  1328.  
  1329. TrackerTypes    CMyDocument::FindOutTrackerServerToUse(void)
  1330.     {
  1331.         SongRec                Temp;
  1332.  
  1333.         if (Selection == -1)
  1334.             {
  1335.                 return eTrackerMarkEspie; /* default.  this should be a fatal error */
  1336.             }
  1337.         ListOfSongs->GetElement(Selection,&Temp);
  1338.         return Temp.Tracker;
  1339.     }
  1340.  
  1341.  
  1342. void                CMyDocument::SetAutoNextSong(MyBoolean NewAutoNextSong)
  1343.     {
  1344.         AutoNextSong = NewAutoNextSong;
  1345.         if (Playing != -1)
  1346.             {
  1347.                 PlayNextWhenThisOneStops = NewAutoNextSong;
  1348.             }
  1349.         if (AutoNextSongBox->State != NewAutoNextSong)
  1350.             {
  1351.                 AutoNextSongBox->DoThang();
  1352.             }
  1353.         UpToDate = False;
  1354.     }
  1355.  
  1356.  
  1357. void                CMyDocument::SetAutoStartSongs(MyBoolean NewAutoStartSongs)
  1358.     {
  1359.         AutoStartSongs = NewAutoStartSongs;
  1360.         if (AutoStartSongsBox->State != NewAutoStartSongs)
  1361.             {
  1362.                 AutoStartSongsBox->DoThang();
  1363.             }
  1364.         UpToDate = False;
  1365.     }
  1366.  
  1367.  
  1368. void                CMyDocument::SetRandomize(MyBoolean NewRandomize)
  1369.     {
  1370.         Randomize = NewRandomize;
  1371.         if (RandomizeBox->State != NewRandomize)
  1372.             {
  1373.                 RandomizeBox->DoThang();
  1374.             }
  1375.         UpToDate = False;
  1376.     }
  1377.  
  1378.  
  1379. void                CMyDocument::SetRepeat(MyBoolean NewRepeat)
  1380.     {
  1381.         Repeat = NewRepeat;
  1382.         if (RepeatBox->State != NewRepeat)
  1383.             {
  1384.                 RepeatBox->DoThang();
  1385.             }
  1386.         UpToDate = False;
  1387.     }
  1388.  
  1389.  
  1390. void                CMyDocument::DoRewind(MyBoolean Flag)
  1391.     {
  1392.         short                SpiffParam;
  1393.  
  1394.         if ((Playing != -1) && PlayerExists)
  1395.             {
  1396.                 if (Flag)
  1397.                     {
  1398.                         SpiffParam = '<';
  1399.                     }
  1400.                  else
  1401.                     {
  1402.                         SpiffParam = '|';
  1403.                     }
  1404.                 SendMessage(SpiffParam,keyKeyPressCharacter);
  1405.             }
  1406.     }
  1407.  
  1408.  
  1409. void                CMyDocument::DoStop(void)
  1410.     {
  1411.         if (Playing != -1)
  1412.             {
  1413.                 CancelCurrentSong();
  1414.             }
  1415.         ResetRandomPlayList();
  1416.         DeregisterIdler(this);
  1417.     }
  1418.  
  1419.  
  1420. void                CMyDocument::DoPlay(void)
  1421.     {
  1422.         SpecificSamplingRateBox->StoreValue();
  1423.         SpecificStereoMixBox->StoreValue();
  1424.         SpecificNumRepeatsBox->StoreValue();
  1425.         SpecificSpeedBox->StoreValue();
  1426.         SpecificVolumeBox->StoreValue();
  1427.         DefaultSamplingRateBox->StoreValue();
  1428.         DefaultStereoMixBox->StoreValue();
  1429.         DefaultNumRepeatsBox->StoreValue();
  1430.         DefaultSpeedBox->StoreValue();
  1431.         DefaultVolumeBox->StoreValue();
  1432.         /* this could either be invoked while playing but paused, or when nothing */
  1433.         /* is playing at all. */
  1434.         if (Playing == -1)
  1435.             {
  1436.                 /* nothing playing; start selected song */
  1437.                 if (Selection != -1)
  1438.                     {
  1439.                         StartThisSong(Selection);
  1440.                     }
  1441.                  else
  1442.                     {
  1443.                         if (Randomize)
  1444.                             {
  1445.                                 StartRandomSong();
  1446.                             }
  1447.                          else
  1448.                             {
  1449.                                 StartThisSong(0);
  1450.                             }
  1451.                     }
  1452.             }
  1453.          else
  1454.             {
  1455.                 CPauseButton*            PauseButton;
  1456.  
  1457.                 /* paused, resume playing */
  1458.                 if (PausePlayButton != NIL)
  1459.                     {
  1460.                         delete PausePlayButton;
  1461.                     }
  1462.                 PauseButton = new CPauseButton;
  1463.                 PausePlayButton = PauseButton;
  1464.                 PauseButton->IPauseButton(this,RootWindow);
  1465.                 if (!RootWindow->Suspended)
  1466.                     {
  1467.                         PauseButton->DoResume();
  1468.                     }
  1469.                 PauseButton->DoUpdate();
  1470.  
  1471.                 /* sending unpause event */
  1472.                 SendMessage(' ',keyKeyPressCharacter);
  1473.             }
  1474.     }
  1475.  
  1476.  
  1477. void                CMyDocument::DoPause(void)
  1478.     {
  1479.         if ((Playing != -1) && PlayerExists)
  1480.             {
  1481.                 CPlayButton*            PlayButton;
  1482.  
  1483.                 /* playing, pause song */
  1484.                 if (PausePlayButton != NIL)
  1485.                     {
  1486.                         delete PausePlayButton;
  1487.                     }
  1488.                 PlayButton = new CPlayButton;
  1489.                 PausePlayButton = PlayButton;
  1490.                 PlayButton->IPlayButton(this,RootWindow);
  1491.                 if (!RootWindow->Suspended)
  1492.                     {
  1493.                         PlayButton->DoResume();
  1494.                     }
  1495.                 PlayButton->DoUpdate();
  1496.  
  1497.                 /* sending pause event */
  1498.                 SendMessage(' ',keyKeyPressCharacter);
  1499.             }
  1500.     }
  1501.  
  1502.  
  1503. void                CMyDocument::DoFastForward(MyBoolean Flag)
  1504.     {
  1505.         short                SpiffParam;
  1506.  
  1507.         if ((Playing != -1) && PlayerExists)
  1508.             {
  1509.                 if (Flag)
  1510.                     {
  1511.                         SpiffParam = '>';
  1512.                     }
  1513.                  else
  1514.                     {
  1515.                         SpiffParam = '|';
  1516.                     }
  1517.                 SendMessage(SpiffParam,keyKeyPressCharacter);
  1518.             }
  1519.     }
  1520.  
  1521.  
  1522. void                CMyDocument::DoSkipToNext(void)
  1523.     {
  1524.         if (Playing != -1)
  1525.             {
  1526.                 if (Randomize)
  1527.                     {
  1528.                         StartRandomSong();
  1529.                     }
  1530.                  else
  1531.                     {
  1532.                         if (Playing < ListOfSongs->GetNumElements() - 1)
  1533.                             {
  1534.                                 StartThisSong(Playing + 1);
  1535.                             }
  1536.                          else
  1537.                             {
  1538.                                 StartThisSong(0);
  1539.                             }
  1540.                     }
  1541.             }
  1542.     }
  1543.  
  1544.  
  1545. void                CMyDocument::DoVolumeUp(void)
  1546.     {
  1547.         if ((Playing != -1) && PlayerExists)
  1548.             {
  1549.                 SendMessage('+',keyKeyPressCharacter);
  1550.             }
  1551.     }
  1552.  
  1553.  
  1554. void                CMyDocument::DoVolumeDown(void)
  1555.     {
  1556.         if ((Playing != -1) && PlayerExists)
  1557.             {
  1558.                 SendMessage('-',keyKeyPressCharacter);
  1559.             }
  1560.     }
  1561.  
  1562.  
  1563. void                CMyDocument::DoIdle(long Stupid)
  1564.     {
  1565.         CPauseButton*                    PauseButton;
  1566.         short                                    Error;
  1567.         AppleEvent                        Event;
  1568.         AEAddressDesc                    AddressDescriptor;
  1569.         AEDesc                                FileList;
  1570.         SongRec                                TheSong;
  1571.         AEDesc                                AEFileDescriptor;
  1572.         short                                    ShortInt;
  1573.         long                                    LongInt;
  1574.         Boolean                                BooleanValue;
  1575.         AEDesc                                TempDesc;
  1576.         AEDesc                                ListElement;
  1577.         long                                    OldPlayer;
  1578.         ProcessSerialNumber        OurPSN;
  1579.         PString                                NewWindowName;
  1580.         Handle                                String1,String2,String3;
  1581.  
  1582.         StackSizeTest();
  1583.         if ((!PlayerExists) && (SongToStart != -1))
  1584.             {
  1585.                 PlayerState = PlayerLaunching;
  1586.                 ListOfSongs->GetElement(SongToStart,&TheSong);
  1587.                 switch (TheSong.Tracker)
  1588.                     {
  1589.                         case eTrackerMarkEspie:
  1590.                             if (Has020orBetter)
  1591.                                 {
  1592.                                     Application->LaunchTracker(TRACKERSERVER68020CREATOR);
  1593.                                 }
  1594.                              else
  1595.                                 {
  1596.                                     Application->LaunchTracker(TRACKERSERVER68000CREATOR);
  1597.                                 }
  1598.                             break;
  1599.                         case eTrackerFrankSeide:
  1600.                             Application->LaunchTracker(FRANKSEIDECREATOR);
  1601.                             break;
  1602.                         case eTrackerAntoineRosset:
  1603.                             Application->LaunchTracker(ROSSETCREATOR);
  1604.                             break;
  1605.                     }
  1606.             }
  1607.         if (PlayerExists && (PlayerState == PlayerWaitingForInit))
  1608.             {
  1609.                 short                    BitTemp;
  1610.  
  1611.  
  1612.                 DeregisterIdler(this);
  1613.  
  1614.                 PlayerState = PlayerRunning;
  1615.                 OldPlayer = Playing;
  1616.                 Playing = SongToStart;
  1617.                 SongToStart = -1;
  1618.                 SongList->Redraw(OldPlayer,OldPlayer);
  1619.                 SongList->Redraw(Playing,Playing);
  1620.  
  1621.                 ListOfSongs->GetElement(Playing,&TheSong);
  1622.                 CheckHeap();
  1623.  
  1624.                 BeginStringOperation();
  1625.                 String1 = PString2Handle(TheFile.name);
  1626.                 RegisterString(String1);
  1627.                 String2 = GetCString(SeparatorID);
  1628.                 RegisterString(String2);
  1629.                 String3 = PString2Handle(TheSong.SongName);
  1630.                 RegisterString(String3);
  1631.                 String1 = ConStr(String1,String2);
  1632.                 String1 = ConStr(String1,String3);
  1633.                 EndStringOperation(String1);
  1634.                 Handle2PString(String1,NewWindowName);
  1635.                 ReleaseHandle(String1);
  1636.                 SetWTitle(RootWindow->MyGrafPtr,NewWindowName);
  1637.  
  1638.                 /* constructing nasty parameter block & sending open event to tracker */
  1639.                 HLock((Handle)this);
  1640.  
  1641.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  1642.                     sizeof(ProcessSerialNumber),&AddressDescriptor);
  1643.  
  1644.                 Error = AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&AddressDescriptor,
  1645.                     kAutoGenerateReturnID,kAnyTransactionID,&Event);
  1646.                 CheckHeap();
  1647.  
  1648.                 Error = AECreateList(NIL,0,False,&FileList);
  1649.                 HLock((Handle)TheSong.SongLocation);
  1650.                 AECreateDesc(typeAlias,(void*)*TheSong.SongLocation,
  1651.                     HandleSize((Handle)TheSong.SongLocation),&ListElement);
  1652.                 HUnlock((Handle)TheSong.SongLocation);
  1653.                 Error = AEPutDesc(&FileList,0,&ListElement);
  1654.                 Error = AEDisposeDesc(&ListElement);
  1655.                 Error = AEPutParamDesc(&Event,keyDirectObject,&FileList);
  1656.                 Error = AEDisposeDesc(&FileList);
  1657.  
  1658.                 if (TheSong.AntiAliasingOverrideDefault)
  1659.                     {
  1660.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.AntiAliasing,
  1661.                             sizeof(MyBoolean),&TempDesc);
  1662.                     }
  1663.                  else
  1664.                     {
  1665.                         Error = AECreateDesc(typeShortInteger,(void*)&AntiAliasing,
  1666.                             sizeof(MyBoolean),&TempDesc);
  1667.                     }
  1668.                 Error = AEPutParamDesc(&Event,keyAntiAliasing,&TempDesc);
  1669.                 Error = AEDisposeDesc(&TempDesc);
  1670.  
  1671.                 if (TheSong.StereoOnOverrideDefault)
  1672.                     {
  1673.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoOn,
  1674.                             sizeof(MyBoolean),&TempDesc);
  1675.                     }
  1676.                  else
  1677.                     {
  1678.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoOn,
  1679.                             sizeof(MyBoolean),&TempDesc);
  1680.                     }
  1681.                 Error = AEPutParamDesc(&Event,keyStereoOn,&TempDesc);
  1682.                 Error = AEDisposeDesc(&TempDesc);
  1683.  
  1684.                 if (TheSong.SamplingRateOverrideDefault)
  1685.                     {
  1686.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.SamplingRate,
  1687.                             sizeof(ushort),&TempDesc);
  1688.                     }
  1689.                  else
  1690.                     {
  1691.                         Error = AECreateDesc(typeShortInteger,(void*)&SamplingRate,
  1692.                             sizeof(ushort),&TempDesc);
  1693.                     }
  1694.                 Error = AEPutParamDesc(&Event,keySamplingRate,&TempDesc);
  1695.                 Error = AEDisposeDesc(&TempDesc);
  1696.  
  1697.                 if (TheSong.NumRepeatsOverrideDefault)
  1698.                     {
  1699.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.NumRepeats,
  1700.                             sizeof(short),&TempDesc);
  1701.                     }
  1702.                  else
  1703.                     {
  1704.                         Error = AECreateDesc(typeShortInteger,(void*)&NumRepeats,
  1705.                             sizeof(short),&TempDesc);
  1706.                     }
  1707.                 Error = AEPutParamDesc(&Event,keyNumRepeats,&TempDesc);
  1708.                 Error = AEDisposeDesc(&TempDesc);
  1709.  
  1710.                 if (TheSong.SpeedOverrideDefault)
  1711.                     {
  1712.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Speed,
  1713.                             sizeof(short),&TempDesc);
  1714.                     }
  1715.                  else
  1716.                     {
  1717.                         Error = AECreateDesc(typeShortInteger,(void*)&Speed,
  1718.                             sizeof(short),&TempDesc);
  1719.                     }
  1720.                 Error = AEPutParamDesc(&Event,keySpeed,&TempDesc);
  1721.                 Error = AEDisposeDesc(&TempDesc);
  1722.  
  1723.                 if (TheSong.StereoMixOverrideDefault)
  1724.                     {
  1725.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoMix,
  1726.                             sizeof(short),&TempDesc);
  1727.                     }
  1728.                  else
  1729.                     {
  1730.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoMix,
  1731.                             sizeof(short),&TempDesc);
  1732.                     }
  1733.                 Error = AEPutParamDesc(&Event,keyStereoMix,&TempDesc);
  1734.                 Error = AEDisposeDesc(&TempDesc);
  1735.  
  1736.                 if (TheSong.VolumeOverrideDefault)
  1737.                     {
  1738.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Volume,
  1739.                             sizeof(short),&TempDesc);
  1740.                     }
  1741.                  else
  1742.                     {
  1743.                         Error = AECreateDesc(typeShortInteger,(void*)&Volume,
  1744.                             sizeof(short),&TempDesc);
  1745.                     }
  1746.                 Error = AEPutParamDesc(&Event,keyLoudness,&TempDesc);
  1747.                 Error = AEDisposeDesc(&TempDesc);
  1748.  
  1749.                 if (UseSixteenBitMode)
  1750.                     {
  1751.                         BitTemp = 16;
  1752.                     }
  1753.                  else
  1754.                     {
  1755.                         BitTemp = 8;
  1756.                     }
  1757.                 Error = AECreateDesc(typeShortInteger,(void*)&BitTemp,
  1758.                     sizeof(short),&TempDesc);
  1759.                 Error = AEPutParamDesc(&Event,keyNumBits,&TempDesc);
  1760.                 Error = AEDisposeDesc(&TempDesc);
  1761.  
  1762.                 Error = GetCurrentProcess(&OurPSN);
  1763.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPSN,
  1764.                     sizeof(ProcessSerialNumber),&TempDesc);
  1765.                 Error = AEPutParamDesc(&Event,keySenderPSN,&TempDesc);
  1766.                 Error = AEDisposeDesc(&TempDesc);
  1767.  
  1768.                 Application->SendMessage(OurPlayer,&Event);
  1769.                 Error = AEDisposeDesc(&AddressDescriptor);
  1770.                 Error = AEDisposeDesc(&Event);
  1771.                 HUnlock((Handle)this);
  1772.  
  1773.                 if (PausePlayButton != NIL)
  1774.                     {
  1775.                         delete PausePlayButton;
  1776.                     }
  1777.                 PauseButton = new CPauseButton;
  1778.                 PausePlayButton = PauseButton;
  1779.                 PauseButton->IPauseButton(this,RootWindow);
  1780.                 if (!RootWindow->Suspended)
  1781.                     {
  1782.                         PauseButton->DoResume();
  1783.                     }
  1784.                 PauseButton->DoUpdate();
  1785.  
  1786.                 StopButton->DoEnable();
  1787.                 RewindButton->DoEnable();
  1788.                 FastForwardButton->DoEnable();
  1789.                 SkipToNextButton->DoEnable();
  1790.             }
  1791.     }
  1792.  
  1793.  
  1794. void                CMyDocument::PlayerDiedNotification(void)
  1795.     {
  1796.         CPlayButton*        PlayButton;
  1797.         long                        OldPlayer;
  1798.  
  1799.         PlayerExists = False;
  1800.         OldPlayer = Playing;
  1801.         Playing = -1;
  1802.         HLock((Handle)this);
  1803.         SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  1804.         HUnlock((Handle)this);
  1805.         SongList->Redraw(OldPlayer,OldPlayer);
  1806.         if (PlayNextWhenThisOneStops)
  1807.             {
  1808.                 if (SongToStart == -1)
  1809.                     {
  1810.                         /* we want to hear the "next" song, but one was not specified. */
  1811.                         if (Randomize)
  1812.                             {
  1813.                                 StartRandomSong();
  1814.                             }
  1815.                          else
  1816.                             {
  1817.                                 if (OldPlayer < ListOfSongs->GetNumElements() - 1)
  1818.                                     {
  1819.                                         StartThisSong(OldPlayer + 1);
  1820.                                     }
  1821.                                  else
  1822.                                     {
  1823.                                         if (Repeat)
  1824.                                             {
  1825.                                                 StartThisSong(0);
  1826.                                             }
  1827.                                          else
  1828.                                             {
  1829.                                                 PlayNextWhenThisOneStops = False;
  1830.                                             }
  1831.                                     }
  1832.                             }
  1833.                     }
  1834.                  else
  1835.                     {
  1836.                         /* they DID specify which song to listen to next */
  1837.                         StartThisSong(SongToStart);
  1838.                     }
  1839.             }
  1840.  
  1841.         delete PausePlayButton;
  1842.         PlayButton = new CPlayButton;
  1843.         PlayButton->IPlayButton(this,RootWindow);
  1844.         PausePlayButton = PlayButton;
  1845.         if (!RootWindow->Suspended)
  1846.             {
  1847.                 PlayButton->DoResume();
  1848.             }
  1849.         PlayButton->DoUpdate();
  1850.  
  1851.         StopButton->DoDisable();
  1852.         RewindButton->DoDisable();
  1853.         FastForwardButton->DoDisable();
  1854.         SkipToNextButton->DoDisable();
  1855.     }
  1856.  
  1857.  
  1858. void                CMyDocument::PlayerLaunchedNotification(ProcessSerialNumber TheProcNum)
  1859.     {
  1860.         StackSizeTest();
  1861.         PlayerExists = True;
  1862.         PlayerState = PlayerWaitingForInit;
  1863.         OurPlayer = TheProcNum;
  1864.     }
  1865.  
  1866.  
  1867. void                CMyDocument::SetNewSelection(long NewSelection)
  1868.     {
  1869.         SpecificSamplingRateBox->StoreValue();
  1870.         SpecificStereoMixBox->StoreValue();
  1871.         SpecificNumRepeatsBox->StoreValue();
  1872.         SpecificSpeedBox->StoreValue();
  1873.         SpecificVolumeBox->StoreValue();
  1874.         DefaultSamplingRateBox->StoreValue();
  1875.         DefaultStereoMixBox->StoreValue();
  1876.         DefaultNumRepeatsBox->StoreValue();
  1877.         DefaultSpeedBox->StoreValue();
  1878.         DefaultVolumeBox->StoreValue();
  1879.         if (Selection != -1)
  1880.             {
  1881.                 long            SelectionTemp;
  1882.  
  1883.                 SelectionTemp = Selection;
  1884.                 Selection = -1;
  1885.                 SongList->Redraw(SelectionTemp,SelectionTemp);
  1886.             }
  1887.         Selection = NewSelection;
  1888.         if (NewSelection == -1)
  1889.             {
  1890.                 CStaticText*        StaticText;
  1891.                 LongPoint                Start,Extent;
  1892.  
  1893.                 SpecificStereoOnBox->DoDisable();
  1894.                 SpecificAntiAliasingBox->DoDisable();
  1895.                 SpecificSamplingRateBox->DoDisable();
  1896.                 SpecificStereoMixBox->DoDisable();
  1897.                 SpecificNumRepeatsBox->DoDisable();
  1898.                 SpecificSpeedBox->DoDisable();
  1899.                 SpecificVolumeBox->DoDisable();
  1900.                 SpecificSamplingRateText->DoDisable();
  1901.                 SpecificStereoMixText->DoDisable();
  1902.                 SpecificNumRepeatsText->DoDisable();
  1903.                 SpecificSpeedText->DoDisable();
  1904.                 SpecificVolumeText->DoDisable();
  1905.                 OverrideStereoOnBox->DoDisable();
  1906.                 OverrideAntiAliasingBox->DoDisable();
  1907.                 OverrideSamplingRateBox->DoDisable();
  1908.                 OverrideStereoMixBox->DoDisable();
  1909.                 OverrideNumRepeatsBox->DoDisable();
  1910.                 OverrideSpeedBox->DoDisable();
  1911.                 OverrideVolumeBox->DoDisable();
  1912.             }
  1913.          else
  1914.             {
  1915.                 LongPoint            Start,Extent;
  1916.                 Handle                String1;
  1917.                 Handle                String2;
  1918.                 Handle                String3;
  1919.                 Handle                String4;
  1920.                 SongRec                TheSong;
  1921.                 CPauseButton*    PauseButton;
  1922.                 CStaticText*    StaticText;
  1923.  
  1924.                 StackSizeTest();
  1925.                 SongList->Redraw(NewSelection,NewSelection);
  1926.                 ListOfSongs->GetElement(NewSelection,&TheSong);
  1927.  
  1928.                 OverrideStereoOnBox->DoEnable();
  1929.                 if (OverrideStereoOnBox->State != TheSong.StereoOnOverrideDefault)
  1930.                     {
  1931.                         OverrideStereoOnBox->DoThang();
  1932.                     }
  1933.                 if (TheSong.StereoOnOverrideDefault)
  1934.                     {
  1935.                         SpecificStereoOnBox->DoEnable();
  1936.                         if (SpecificStereoOnBox->State != TheSong.StereoOn)
  1937.                             {
  1938.                                 SpecificStereoOnBox->DoThang();
  1939.                             }
  1940.                     }
  1941.                  else
  1942.                     {
  1943.                         SpecificStereoOnBox->DoDisable();
  1944.                     }
  1945.  
  1946.                 OverrideAntiAliasingBox->DoEnable();
  1947.                 if (OverrideAntiAliasingBox->State != TheSong.AntiAliasingOverrideDefault)
  1948.                     {
  1949.                         OverrideAntiAliasingBox->DoThang();
  1950.                     }
  1951.                 if (TheSong.AntiAliasingOverrideDefault)
  1952.                     {
  1953.                         SpecificAntiAliasingBox->DoEnable();
  1954.                         if (SpecificAntiAliasingBox->State != TheSong.AntiAliasing)
  1955.                             {
  1956.                                 SpecificAntiAliasingBox->DoThang();
  1957.                             }
  1958.                     }
  1959.                  else
  1960.                     {
  1961.                         SpecificAntiAliasingBox->DoDisable();
  1962.                     }
  1963.  
  1964.                 OverrideSamplingRateBox->DoEnable();
  1965.                 if (OverrideSamplingRateBox->State != TheSong.SamplingRateOverrideDefault)
  1966.                     {
  1967.                         OverrideSamplingRateBox->DoThang();
  1968.                     }
  1969.                 if (TheSong.SamplingRateOverrideDefault)
  1970.                     {
  1971.                         SpecificSamplingRateBox->DoEnable();
  1972.                         SpecificSamplingRateText->DoEnable();
  1973.                         SpecificSamplingRateBox->SetValue(TheSong.SamplingRate);
  1974.                     }
  1975.                  else
  1976.                     {
  1977.                         SpecificSamplingRateBox->DoDisable();
  1978.                         SpecificSamplingRateText->DoDisable();
  1979.                     }
  1980.  
  1981.                 OverrideStereoMixBox->DoEnable();
  1982.                 if (OverrideStereoMixBox->State != TheSong.StereoMixOverrideDefault)
  1983.                     {
  1984.                         OverrideStereoMixBox->DoThang();
  1985.                     }
  1986.                 if (TheSong.StereoMixOverrideDefault)
  1987.                     {
  1988.                         SpecificStereoMixBox->DoEnable();
  1989.                         SpecificStereoMixText->DoEnable();
  1990.                         SpecificStereoMixBox->SetValue(TheSong.StereoMix);
  1991.                     }
  1992.                  else
  1993.                     {
  1994.                         SpecificStereoMixBox->DoDisable();
  1995.                         SpecificStereoMixText->DoDisable();
  1996.                     }
  1997.  
  1998.                 OverrideNumRepeatsBox->DoEnable();
  1999.                 if (OverrideNumRepeatsBox->State != TheSong.NumRepeatsOverrideDefault)
  2000.                     {
  2001.                         OverrideNumRepeatsBox->DoThang();
  2002.                     }
  2003.                 if (TheSong.NumRepeatsOverrideDefault)
  2004.                     {
  2005.                         SpecificNumRepeatsBox->DoEnable();
  2006.                         SpecificNumRepeatsText->DoEnable();
  2007.                         SpecificNumRepeatsBox->SetValue(TheSong.NumRepeats);
  2008.                     }
  2009.                  else
  2010.                     {
  2011.                         SpecificNumRepeatsBox->DoDisable();
  2012.                         SpecificNumRepeatsText->DoDisable();
  2013.                     }
  2014.  
  2015.                 OverrideSpeedBox->DoEnable();
  2016.                 if (OverrideSpeedBox->State != TheSong.SpeedOverrideDefault)
  2017.                     {
  2018.                         OverrideSpeedBox->DoThang();
  2019.                     }
  2020.                 if (TheSong.SpeedOverrideDefault)
  2021.                     {
  2022.                         SpecificSpeedBox->DoEnable();
  2023.                         SpecificSpeedText->DoEnable();
  2024.                         SpecificSpeedBox->SetValue(TheSong.Speed);
  2025.                     }
  2026.                  else
  2027.                     {
  2028.                         SpecificSpeedBox->DoDisable();
  2029.                         SpecificSpeedText->DoDisable();
  2030.                     }
  2031.  
  2032.                 OverrideVolumeBox->DoEnable();
  2033.                 if (OverrideVolumeBox->State != TheSong.VolumeOverrideDefault)
  2034.                     {
  2035.                         OverrideVolumeBox->DoThang();
  2036.                     }
  2037.                 if (TheSong.VolumeOverrideDefault)
  2038.                     {
  2039.                         SpecificVolumeBox->DoEnable();
  2040.                         SpecificVolumeText->DoEnable();
  2041.                         SpecificVolumeBox->SetValue(TheSong.Volume);
  2042.                     }
  2043.                  else
  2044.                     {
  2045.                         SpecificVolumeBox->DoDisable();
  2046.                         SpecificVolumeText->DoDisable();
  2047.                     }
  2048.             }
  2049.     }
  2050.  
  2051.  
  2052. void                CMyDocument::MoveSong(long SongIndex, long NewIndex)
  2053.     {
  2054.         SongRec            MySong;
  2055.         long                OldSelection;
  2056.         long                Temp;
  2057.  
  2058.         UpToDate = False;
  2059.         SpecificSamplingRateBox->StoreValue();
  2060.         SpecificStereoMixBox->StoreValue();
  2061.         SpecificNumRepeatsBox->StoreValue();
  2062.         SpecificSpeedBox->StoreValue();
  2063.         SpecificVolumeBox->StoreValue();
  2064.         DefaultSamplingRateBox->StoreValue();
  2065.         DefaultStereoMixBox->StoreValue();
  2066.         DefaultNumRepeatsBox->StoreValue();
  2067.         DefaultSpeedBox->StoreValue();
  2068.         DefaultVolumeBox->StoreValue();
  2069.  
  2070.         OldSelection = Playing;
  2071.         Playing = -1;
  2072.         SongList->Redraw(OldSelection,OldSelection);
  2073.         Playing = OldSelection;
  2074.         if (Playing == SongIndex)
  2075.             {
  2076.                 Playing = NewIndex;
  2077.                 if (NewIndex > SongIndex)
  2078.                     {
  2079.                         Playing -= 1;
  2080.                     }
  2081.             }
  2082.          else
  2083.             {
  2084.                 if (SongIndex < NewIndex)
  2085.                     {
  2086.                         if ((Playing > SongIndex) && (Playing < NewIndex))
  2087.                             {
  2088.                                 Playing -= 1;
  2089.                             }
  2090.                     }
  2091.                  else
  2092.                     {
  2093.                         if ((Playing >= NewIndex) && (Playing < SongIndex))
  2094.                             {
  2095.                                 Playing += 1;
  2096.                             }
  2097.                     }
  2098.             }
  2099.         SongList->Redraw(Playing,Playing);
  2100.  
  2101.         OldSelection = Selection;
  2102.         Selection = -1;
  2103.         SongList->Redraw(OldSelection,OldSelection);
  2104.         if ((SongIndex < 0) || (SongIndex >= ListOfSongs->GetNumElements()))
  2105.             {
  2106.                 return;
  2107.             }
  2108.         if (NewIndex < 0)
  2109.             {
  2110.                 NewIndex = 0;
  2111.             }
  2112.         ListOfSongs->GetElement(SongIndex,&MySong);
  2113.         ListOfSongs->DeleteElement(SongIndex);
  2114.         if (NewIndex > SongIndex)
  2115.             {
  2116.                 NewIndex -= 1;
  2117.             }
  2118.         NewIndex = ListOfSongs->InsertElement(NewIndex);
  2119.         ListOfSongs->PutElement(NewIndex,&MySong);
  2120.         Selection = NewIndex;
  2121.         if (SongIndex > NewIndex)
  2122.             {
  2123.                 Temp = SongIndex;
  2124.                 SongIndex = NewIndex;
  2125.                 NewIndex = Temp;
  2126.             }
  2127.         SongList->Redraw(SongIndex,NewIndex);
  2128.     }
  2129.  
  2130.  
  2131. void                CMyDocument::ResetRandomPlayList(void)
  2132.     {
  2133.         long                Scan;
  2134.         long                End;
  2135.         SongRec            Temp;
  2136.  
  2137.         End = ListOfSongs->GetNumElements();
  2138.         for (Scan = 0; Scan < End; Scan += 1)
  2139.             {
  2140.                 ListOfSongs->GetElement(Scan,&Temp);
  2141.                 Temp.PlayedFlag = False;
  2142.                 ListOfSongs->PutElement(Scan,&Temp);
  2143.             }
  2144.     }
  2145.  
  2146.  
  2147. void                CMyDocument::StartRandomSong(void)
  2148.     {
  2149.         short                RunoutCount;
  2150.         long                Possibility;
  2151.         long                NumSongs;
  2152.         SongRec            Temp;
  2153.         long                StartingPoint;
  2154.  
  2155.         /* randomly look for a song that hasn't been played.  If we */
  2156.         /* can't find one then do a linear search for one.  If we fail that */
  2157.         /* then there are no more: reset and play if <repeat> is on, otherwise */
  2158.         /* just stop. */
  2159.         CancelCurrentSong();
  2160.      TryAgainPoint:
  2161.         NumSongs = ListOfSongs->GetNumElements();
  2162.         if (NumSongs == 0)
  2163.             {
  2164.                 return; /* oops, can't play anything */
  2165.             }
  2166.         RunoutCount = MAXRANDOMTRIESBEFOREGIVINGUP;
  2167.         while (RunoutCount > 0)
  2168.             {
  2169.                 Possibility = ((unsigned short)Random()) % NumSongs;
  2170.                 ListOfSongs->GetElement(Possibility,&Temp);
  2171.                 if (!Temp.PlayedFlag)
  2172.                     {
  2173.                         /* found one to play */
  2174.                      FoundOnePoint:
  2175.                         StartThisSong(Possibility);
  2176.                         return;
  2177.                     }
  2178.                 RunoutCount -= 1;
  2179.             }
  2180.         /* failed random search.  Do linear search */
  2181.         StartingPoint = Possibility;
  2182.         do
  2183.             {
  2184.                 Possibility += 1;
  2185.                 if (Possibility >= NumSongs)
  2186.                     {
  2187.                         Possibility = 0;
  2188.                     }
  2189.                 ListOfSongs->GetElement(Possibility,&Temp);
  2190.                 if (!Temp.PlayedFlag)
  2191.                     {
  2192.                         goto FoundOnePoint;
  2193.                     }
  2194.             } while (Possibility != StartingPoint);
  2195.         /* failed that!  Reset and try again. */
  2196.         if (Repeat)
  2197.             {
  2198.                 /* there is no possible way to get into an infinite loop. */
  2199.                 ResetRandomPlayList();
  2200.                 goto TryAgainPoint;
  2201.             }
  2202.     }
  2203.  
  2204.  
  2205. /* this sends control events to the remote player.  Note that it only */
  2206. /* supports short integer messages, but that's ok because they're all shorts */
  2207. void                CMyDocument::SendMessage(short TheMessage, DescType TheKeyWord)
  2208.     {
  2209.         short                        Error;
  2210.         AppleEvent            Event;
  2211.         AEAddressDesc        AddressDescriptor;
  2212.         short                        KeyPress;
  2213.  
  2214.         HLock((Handle)this); /* make sure the OurPlayer variable doesn't move */
  2215.         Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  2216.             sizeof(ProcessSerialNumber),&AddressDescriptor);
  2217.         HUnlock((Handle)this);
  2218.         Error = AECreateAppleEvent(ControlEventClass,ControlEvent,&AddressDescriptor,
  2219.             kAutoGenerateReturnID,kAnyTransactionID,&Event);
  2220.         Error = AEPutParamPtr(&Event,TheKeyWord,typeShortInteger,
  2221.             (void*)&TheMessage,sizeof(short));
  2222.         Application->SendMessage(OurPlayer,&Event);
  2223.         Error = AEDisposeDesc(&AddressDescriptor);
  2224.         Error = AEDisposeDesc(&Event);
  2225.         HUnlock((Handle)this);
  2226.     }
  2227.